#!/bin/sh


if [ $# -ne 0 ]; then

	echo "usage : $0 upmefile"

	exit

fi
tag=`find .|grep 001_ |grep md|sort -g |head -1 |sed -e "s/.*\///" |awk -F "001"  '{print $1}'|sed -e "s/[1234567890]//g" |head -1`

if [ "$tag" = "" ]; then
	echo "不是书籍目录"
	exit -1
fi

rm -f config

url=`echo $tag |tr 'A-Z' 'a-z'`

bookname=`pwd| awk -F\/ '{print $NF}'`

bookdir=`pwd`

basedir="/Users/hbaolong/workshop/hbaolong.github.io"

ls -l  $tag*.md >tmp.md 

allchapter=`cat tmp.md |sed -e "/^l/d" |grep $tag  |wc | awk '{print $1}'`

alldays=`wc tmp.md | awk '{print $1}'`

startdate=`head -1 tmp.md | sed -e "s/-\>.*//g"|awk '{print $NF}' |sed -e "s/.*_//g" | sed -e "s/-.*//g"`

enddate=`tail -1 tmp.md | sed -e "s/->.*//g" | awk '{print $NF}' |sed -e "s/.*_//g" | sed -e "s/-.*//g"`

if [ -e wordcounter.md ]; then 
	words=`awk '{printf $1 " + " }' wordcounter.md |sed -e "s/+ $//" `
	allwords=`expr $words`
fi

rm -f tmp.md

echo "url=/3place/"$url >>config
echo "tag="$tag >> config
echo "bookname="$bookname >> config
echo "bookdir="$bookdir >> config
echo "basedir="$basedir >> config
echo "allchapter="$allchapter >> config
echo "startdate="$startdate >> config
echo "enddate="$enddate >> config
echo "alldays="$alldays >> config
echo "allwords="$allwords >> config

cat config